//
//  lookingForSubsidiesViewModel.m
//  GLGW_Shoping
//
//  Created by whx on 2018/12/7.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "lookingForSubsidiesViewModel.h"
#import "NoDataFootTableViewHeaderFooterView.h"
#import "WithDrawlRecordDetailTableViewCell.h"
#import "lookingForSubsidiesTableViewCell.h"

@interface lookingForSubsidiesViewModel ()<UITableViewDelegate, UITableViewDataSource>
{
    UITableView *selfTableView;
    NSMutableArray *leftArr;
}

@end

@implementation lookingForSubsidiesViewModel

- (instancetype)initWithViewToViewModel:(UITableView *)tableView theSuperView:(UIView *)superView
{
    if (self = [super initWithViewToViewModel:tableView theSuperView:superView]) {
        NSMutableArray *liArr = [NSMutableArray arrayWithObjects:@"佣金金额", @"佣金类型", @"发放时间", nil];
        leftArr = [NSMutableArray arrayWithObjects:liArr, nil];
        tableView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
        tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.sectionFooterHeight = 0.0;
        tableView.sectionHeaderHeight = 0.0;
        [tableView registerClass:[NoDataFootTableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"NoDataFootTableViewHeaderFooterView"];
        [superView addSubview:tableView];
        selfTableView = tableView;
    }
    return self;
}

- (void)setType:(SubsidiesType)type
{
    _type = type;
    NSArray *diArr;
    NSString *titleStr;
    if (type == SubsidiesType_LookingFor) {
        titleStr = @"求购补贴";
        diArr = @[@"查看相关订单"];
    } else if (type == SubsidiesType_Offer) {
        titleStr = @"报价补贴";
        diArr = @[@"查看相关求购单"];
    } else if (type == SubsidiesType_Order) {
        titleStr = @"订单补贴";
        NSMutableArray *arr = leftArr[0];
        [arr addObject:@"备注"];
        diArr = @[@"查看相关报价"];
    } else if (type == SubsidiesType_Forwarding) {
        titleStr = @"转发补贴";
        diArr = @[@"查看相关文章"];
    } else if (type == SubsidiesType_Browse) {
        titleStr = @"浏览补贴";
        diArr = @[@"查看相关文章"];
    }
    [leftArr addObject:diArr];
    [selfTableView reloadData];
    if (self.BlockTitle) {
        self.BlockTitle(titleStr);
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return kHeightProportion_In_iPhoneTriploid(9);
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    NoDataFootTableViewHeaderFooterView *footer = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"NoDataFootTableViewHeaderFooterView"];
    return footer;
}

#pragma mark - tableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return leftArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [leftArr[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WithDrawlRecordDetailTableViewCell *detailCell = [WithDrawlRecordDetailTableViewCell cellWithTableView:tableView];
    if (indexPath.section == 1) {
        detailCell.leftColorStr = @"#333333";
        detailCell.rightLab.hidden = YES;
        detailCell.showPush = YES;
    } else {
        detailCell.leftColorStr = @"#999999";
        detailCell.rightLab.hidden = NO;
        detailCell.showPush = NO;
    }
    if (indexPath.row == 0 && indexPath.section == 0) {
        detailCell.rightLab.textColor = [UIColor colorWithHexString:@"#EC5353"];
    } else {
        detailCell.rightLab.textColor = kColor_Rule_Black;
        
    }
    detailCell.leftStr = leftArr[indexPath.section][indexPath.row];
    if (self.type == SubsidiesType_Order) {
        if (indexPath.row == 3) {
            lookingForSubsidiesTableViewCell *cell = [lookingForSubsidiesTableViewCell cellWithTableView:tableView];
            return cell;            
        }
    }
    return detailCell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1) {
        if (self.BlockSelet) {
            self.BlockSelet(indexPath);
        }
    }
}

@end
